package com.cinco.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cinco.server.pojo.MenuRole;
import com.cinco.server.mapper.MenuRoleMapper;
import com.cinco.server.pojo.Result;
import com.cinco.server.service.IMenuRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author cinco
 * @since 2022-01-11
 */
@Service
@Transactional
public class MenuRoleServiceImpl extends ServiceImpl<MenuRoleMapper, MenuRole> implements IMenuRoleService {
    /**
     * 更新角色菜单
     * @param rid
     * @param mids
     * @return
     */
    @Override
    public Result updateMenuRole(Integer rid, Integer[] mids) {
        baseMapper.delete(new QueryWrapper<MenuRole>().eq("rid",rid));
        //mids为空的话直接返回成功信息即可
        if (null == mids || 0== mids.length){
            return Result.success("更新成功！");
        }
        Integer record = baseMapper.insertRecord(rid, mids);
        //插入成功记录数 等于 mids长度时 就更新成功了
        if (record == mids.length){
            return Result.success("更新成功！");
        }
        return Result.error("更新失败!");
    }
}
